
package com.jf.cloud.product.feign;

import cn.hutool.core.collection.CollUtil;
import com.jf.cloud.api.auth.constant.SysTypeEnum;
import com.jf.cloud.api.multishop.feign.ShopSubstituteSalesFeignClient;
import com.jf.cloud.api.product.bo.SpuSimpleBO;
import com.jf.cloud.api.product.feign.SpuFeignClient;
import com.jf.cloud.api.product.util.ProductLangUtil;
import com.jf.cloud.common.constant.Constant;
import com.jf.cloud.common.constant.StatusEnum;
import com.jf.cloud.common.product.bo.EsProductBO;
import com.jf.cloud.common.product.constant.*;
import com.jf.cloud.common.product.dto.SpuDTO;
import com.jf.cloud.common.product.vo.*;
import com.jf.cloud.common.product.vo.search.ProductSearchVO;
import com.jf.cloud.common.product.vo.search.SpuAdminVO;
import com.jf.cloud.common.product.vo.search.SpuSearchVO;
import com.jf.cloud.common.response.ResponseEnum;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.product.bo.CategoryRateBO;
import com.jf.cloud.product.model.SkuStock;
import com.jf.cloud.product.model.Spu;
import com.jf.cloud.product.model.SpuConsignmentChange;
import com.jf.cloud.product.service.*;
import com.jf.cloud.product.vo.SkuStockVO;
import io.swagger.v3.oas.annotations.Hidden;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author zz
 * @date 2020/12/8
 */
@RestController
@Hidden
public class SpuFeignController implements SpuFeignClient {

    @Autowired
    private SpuService spuService;
    @Autowired
    private SkuService skuService;
    @Autowired
    private CategoryShopService categoryShopService;

    @Autowired
    private SpuExtensionService spuExtensionService;
    @Autowired
    private MapperFacade mapperFacade;
    @Autowired
    private ShopSubstituteSalesFeignClient shopSubstituteSalesFeignClient;
    @Autowired
    private SupplierSpuUpdateLaterOperateService supplierSpuUpdateLaterOperateService;
    @Autowired
    private SpuConsignmentChangeService spuConsignmentChangeService;
    @Autowired
    private SkuStockService skuStockService;


    @Override
    public ServerResponseEntity<SpuVO> getById(Long spuId) {
        SpuVO spuVO = spuService.getBySpuId(spuId);
        ProductLangUtil.spu(spuVO);
        SpuVO spu = new SpuVO();
        spu.setSpuId(spuVO.getSpuId());
        spu.setName(spuVO.getName());
        spu.setSellingPoint(spuVO.getSellingPoint());
        spu.setMainImgUrl(spuVO.getMainImgUrl());
        spu.setStatus(spuVO.getStatus());
        spu.setSupplierDeliveryType(spuVO.getSupplierDeliveryType());
        spu.setSupplierSpuType(spuVO.getSupplierSpuType());
        spu.setSupplierSpuId(spuVO.getSupplierSpuId());
        spu.setSpuType(spuVO.getSpuType());
        spu.setSpuMold(spuVO.getSpuMold());
        spu.setIsRefund(spuVO.getIsRefund());
        spu.setWriteOffNum(spuVO.getWriteOffNum());
        spu.setWriteOffMultipleCount(spuVO.getWriteOffMultipleCount());
        spu.setWriteOffTime(spuVO.getWriteOffTime());
        spu.setWriteOffStart(spuVO.getWriteOffStart());
        spu.setWriteOffEnd(spuVO.getWriteOffEnd());
        return ServerResponseEntity.success(spu);
    }

    @Override
    public ServerResponseEntity<SpuVO> getDetailById(Long spuId) {
        SpuVO spuVO = spuService.getBySpuId(spuId);
        ProductLangUtil.spu(spuVO);
        return ServerResponseEntity.success(spuVO);
    }

    @Override
    public ServerResponseEntity<SpuAndSkuVO> getSpuAndSkuAndRateById(Long spuId, Long skuId, Boolean supplierSpuType) {
        SpuVO spu = spuService.getBySpuId(spuId);
        SkuVO sku = skuService.getSkuBySkuId(skuId);
        // 当商品状态不正常时，不能添加到购物车
        boolean spuIsNotExist = Objects.isNull(spu) || Objects.isNull(sku) || !Objects.equals(spu.getStatus(), StatusEnum.ENABLE.value()) || !Objects.equals(sku.getStatus(), StatusEnum.ENABLE.value()) || !Objects.equals(sku.getSpuId(), spu.getSpuId());
        if (spuIsNotExist) {
            // 当返回商品不存在时，前端应该将商品从购物车界面移除
            return ServerResponseEntity.fail(ResponseEnum.SPU_NOT_EXIST);
        }
//        Integer sysType = supplierSpuType ? SysTypeEnum.SUPPLIER.value() : SysTypeEnum.MULTISHOP.value();
//        Long shopId = supplierSpuType ? spu.getSupplierId() : spu.getShopId();
        List<CategoryRateBO> shopCategoryRates = categoryShopService.listRateByShopId(spu.getShopId(), SysTypeEnum.MULTISHOP.value());
        spu.setRate(0.0);
        for (CategoryRateBO shopCategoryRate : shopCategoryRates) {
            if (Objects.equals(shopCategoryRate.getCategoryId(), spu.getCategoryId())) {
                spu.setRate(shopCategoryRate.getRate());
            }
        }
        //获取代销商品基本信息是否改变
        SpuConsignmentChange spuConsignmentChange = spuConsignmentChangeService.getBySpuId(spuId);
        // 判断下是否为供应商商品,如果是商家代销供应商商品且为供应商发货设置供应商信息
        if (!Objects.equals(spu.getSupplierId(), 0L) && Objects.equals(spu.getSupplierDeliveryType(), 1)) {
            SpuVO supplierSpu = spuService.getBySpuId(spu.getSupplierSpuId());
            SkuVO supplierSku = skuService.getSkuBySkuId(sku.getSupplierSkuId());
            //名称
            if (Objects.nonNull(spuConsignmentChange) && Objects.equals(spuConsignmentChange.getNameChange(), 0)) {
                if (Objects.equals(spu.getSupplierDeliveryType(), SupplierDeliveryType.SUPPLIER_DELIVERY.value())) {
                    spu.setName(supplierSpu.getName());
                }
            }
            spu.setDeliveryTemplateId(supplierSpu.getDeliveryTemplateId());
            sku.setSupplyPriceFee(supplierSku.getPriceFee());
            List<CategoryRateBO> supplierCategoryRates = categoryShopService.listRateByShopId(spu.getSupplierId(), SysTypeEnum.SUPPLIER.value());
            spu.setSupplierRate(0.0);
            for (CategoryRateBO supplierCategoryRate : supplierCategoryRates) {
                if (Objects.equals(supplierCategoryRate.getCategoryId(), spu.getCategoryId())) {
                    spu.setSupplierRate(supplierCategoryRate.getRate());
                }
            }
        }
        SpuAndSkuVO spuAndSku = new SpuAndSkuVO();
        spuAndSku.setSku(sku);
        spuAndSku.setSpu(spu);
        return ServerResponseEntity.success(spuAndSku);
    }

    @Override
    public ServerResponseEntity<List<SpuVO>> listCanSeckillProd(Long spuId, Long shopId) {
        return ServerResponseEntity.success(spuService.listCanSeckillProd(spuId, shopId));
    }

    @Override
    public ServerResponseEntity<List<PurchaseSpuVO>> listPurchaseSpuByPartyCodeList(List<String> partyCodeList, Long shopId) {
        List<SkuVO> skuList = skuService.listByPartyCodeList(partyCodeList);
        // 查询商家对应供应商商品的库存信息
        List<SkuStockVO> shopSkuStockVO = skuStockService.listShopStockByPartyCodesAndShopId(partyCodeList, shopId);
        Map<String, Integer> shopSkuStockMap = shopSkuStockVO.stream().collect(Collectors.toMap(SkuStockVO::getPartyCode, SkuStockVO::getStock));
        List<PurchaseSpuVO> purchaseSpuList = new ArrayList<>();
        for (SkuVO skuVO : skuList) {
            PurchaseSpuVO purchaseSpuVO = new PurchaseSpuVO();
            SpuVO spuVO = spuService.getBySpuId(skuVO.getSpuId());
            ProductLangUtil.spu(spuVO);
            ProductLangUtil.sku(skuVO);
            SkuStock skuStock = skuStockService.getBySkuId(skuVO.getSkuId());
            purchaseSpuVO.setSkuId(skuVO.getSkuId());
            purchaseSpuVO.setPartyCode(skuVO.getPartyCode());
            purchaseSpuVO.setPriceFee(skuVO.getPriceFee());
            purchaseSpuVO.setImgUrl(skuVO.getImgUrl());
            purchaseSpuVO.setSpuId(skuVO.getSpuId());
            purchaseSpuVO.setName(spuVO.getName());
            purchaseSpuVO.setSkuName(skuVO.getSkuName());
            purchaseSpuVO.setMainImgUrl(spuVO.getMainImgUrl());
            purchaseSpuVO.setStock(shopSkuStockMap.getOrDefault(skuVO.getPartyCode(), 0));
            purchaseSpuVO.setSupplierStock(skuStock.getStock());
            purchaseSpuVO.setSupplierId(spuVO.getSupplierId());
            purchaseSpuList.add(purchaseSpuVO);
        }
        return ServerResponseEntity.success(purchaseSpuList);
    }

    @Override
    public ServerResponseEntity<SpuActivityAppVO> spuActivityBySpuId(Long shopId, Long spuId) {
        return ServerResponseEntity.success(spuService.spuActivityBySpuId(shopId, spuId));
    }

    @Override
    public ServerResponseEntity<Void> offlineSpuBySupplierId(Long supplierId) {
        spuService.offlineSpuBySupplierId(supplierId);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<Void> offlineSpuByShopId(Long shopId) {
        spuService.offlineSpuByShopId(shopId);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<Void> offlineSpuByShopIds(List<Long> shopIds) {
        spuService.offlineSpuByShopIds(3, shopIds);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<SpuVO> getSpuAndSkuBySpuId(Long spuId) {
        SpuVO spuVO = spuService.getBySpuId(spuId);
        ProductLangUtil.spu(spuVO);
        // sku信息
        if (Objects.equals(spuVO.getSupplierSpuType(), SupplierSpuType.CONSIGNMENT.value())){
            //代销商品
            spuVO.setSkus(skuService.listConsignmentSku(spuVO,false));
        }else {
            //其他商品（商家商品，供应商商品）
            spuVO.setSkus(skuService.listSkuAllInfoBySpuId(spuId, false));
        }
        return ServerResponseEntity.success(spuVO);
    }

    @Override
    public ServerResponseEntity<Void> changeSpuType(SpuDTO spuDTO) {
        Spu spu = mapperFacade.map(spuDTO, Spu.class);
        spuService.updateSpu(spu);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<Integer> countByTransportId(Long transportId) {

        return ServerResponseEntity.success(spuService.countByTransportId(transportId));
    }

    @Override
    public void removeSpuActivityCache(Long shopId, List<Long> spuIds) {
        if (Objects.equals(shopId, Constant.PLATFORM_SHOP_ID)) {
            shopId = null;
        }
        if (CollUtil.isEmpty(spuIds) && !Objects.equals(shopId, Constant.PLATFORM_SHOP_ID)) {
            spuIds = spuService.listSpuIdsByShopId(shopId);
        }
        spuService.batchRemoveSpuActivityCache(spuIds);
    }

    @Override
    public void changeToNormalSpu(List<Long> spuIds) {
        spuService.changeToNormalSpu(spuIds);
    }

    @Override
    public ServerResponseEntity<Integer> countByUserId(Long userId) {
        return ServerResponseEntity.success(spuService.countByUserId(userId));
    }

    @Override
    public ServerResponseEntity<List<SpuVO>> listSpuNameBySpuIds(List<Long> spuIds) {
        return ServerResponseEntity.success(spuService.listSpuNameBySpuIds(spuIds));
    }

    @Override
    public ServerResponseEntity<List<SpuVO>> listSpuBySpuIds(List<Long> spuIds) {
        return ServerResponseEntity.success(spuService.listSpuBySpuIds(spuIds));
    }

    @Override
    public ServerResponseEntity<Void> updateSpuUpdateTimeByShopIds(List<Long> shopIds, Integer sysType) {
        spuService.updateSpuUpdateTime(null, null, shopIds, sysType);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<Void> offlineSpuActivityByShopIds(List<Long> shopIds) {
        spuService.offlineSpuByShopIds(1, shopIds);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<List<SpuSimpleBO>> listSimple(SpuSimpleBO spuSimpleBO) {
        List<SpuSimpleBO> spus = spuService.listSimple(spuSimpleBO);
        return ServerResponseEntity.success(spus);
    }

    @Override
    public ServerResponseEntity<List<SpuSimpleBO>> listSimples(SpuSimpleBO spuSimpleBO) {
        List<SpuSimpleBO> spus = spuService.listSimples(spuSimpleBO);
        return ServerResponseEntity.success(spus);
    }

    @Override
    public ServerResponseEntity<List<SkuVO>> listSkuPriceByIds(List<Long> skuIds) {
        return ServerResponseEntity.success(skuService.listSkuPriceByIds(skuIds));
    }

    @Override
    public ServerResponseEntity<List<Long>> listSpuIdsByShopId(Long shopId) {
        return ServerResponseEntity.success(spuService.listSpuIdsByShopIds(Collections.singletonList(shopId)));
    }


    @Override
    public ServerResponseEntity<?> checkSpuStatus(List<Long> spuIds) {
        return spuService.checkSpuStatus(spuIds);
    }

    @Override
    public ServerResponseEntity<List<SpuAndSkuVO>> listSpuAndSkuById(List<SkuVO> skuList, Long supplierId) {
        List<SpuAndSkuVO> spuAndSkuList = new ArrayList<>();
        for (SkuVO skuVO : skuList) {
            SpuVO spu = spuService.getBySpuId(skuVO.getSpuId());
            SkuVO sku = skuService.getSkuBySkuId(skuVO.getSkuId());
            // 当商品状态不正常时，不能添加到购物车
            boolean spuIsNotExist = Objects.isNull(spu) || Objects.isNull(sku) || !Objects.equals(spu.getStatus(), StatusEnum.ENABLE.value()) || !Objects.equals(sku.getStatus(), StatusEnum.ENABLE.value()) || !Objects.equals(sku.getSpuId(), spu.getSpuId());
            if (spuIsNotExist) {
                // 当返回商品不存在时，前端应该将商品从购物车界面移除
                return ServerResponseEntity.fail(ResponseEnum.SPU_NOT_EXIST);
            }
            SpuAndSkuVO spuAndSku = new SpuAndSkuVO();
            spuAndSku.setSkuId(sku.getSkuId());
            spuAndSku.setSpuId(sku.getSpuId());
            spuAndSku.setSku(sku);
            spuAndSku.setSpu(spu);
            spuAndSkuList.add(spuAndSku);
        }
        return ServerResponseEntity.success(spuAndSkuList);
    }

    @Override
    public ServerResponseEntity<List<SpuAdminVO>> isCommissionByShopIdAndSpuId(List<SpuAdminVO> spuAdminVOS, Long shopId) {
        //获取代销商品状态
        List<Long> supplierIds = spuAdminVOS.stream().map(e -> e.getSpuId()).collect(Collectors.toList());
        //获取代销商品信息
        if (CollUtil.isEmpty(supplierIds) || supplierIds.size() == 0){
            return ServerResponseEntity.success(spuAdminVOS);
        }
        List<SpuVO> spuVOS = spuService.listSpuByShopIdAndSupplierSpuId(shopId, supplierIds);
        Map<Long, List<SpuVO>> listMap = spuVOS.stream().collect(Collectors.groupingBy(SpuVO::getSupplierSpuId));
        Map<Long, Long> commissionSpuIds = spuVOS.stream().collect(Collectors.toMap(SpuVO::getSupplierSpuId, SpuVO::getSpuId));
        for (SpuAdminVO spuAdminVO : spuAdminVOS) {
            //根据供应商品id和商家id获取代销商品信息
            SpuVO commissionSpu = spuService.getSpuByShopIdAndSupplierSpuId(shopId, spuAdminVO.getSpuId());
            if (Objects.nonNull(commissionSpu)){
                //判断代销商品是否选择了店铺分类
                if (Objects.nonNull(commissionSpu.getShopCategoryId()) && commissionSpu.getShopCategoryId() == -1){
                    spuAdminVO.setIsSynUpdate(IsSynUpdate.NO_CHANGE.value());
                }
            }
            List<SpuVO> spuVOS1 = listMap.get(spuAdminVO.getSpuId());
            Long commissionSpuId = commissionSpuIds.get(spuAdminVO.getSpuId());
            if (!Objects.isNull(spuVOS1)) {
                if (spuVOS1.get(0).getStatus().equals(SpuStatus.PUT_SHELF.value())) {
                    spuAdminVO.setIsPut(SpuStatus.PUT_SHELF.value());
                }
                if (spuVOS1.get(0).getStatus().equals(SpuStatus.OFF_SHELF.value())) {
                    spuAdminVO.setIsPut(SpuStatus.OFF_SHELF.value());
                }
            }
            if (!Objects.isNull(commissionSpuId)) {
                spuAdminVO.setCommissionSpuId(commissionSpuId);
            }
            spuAdminVO.setIsCommission(IsCommission.NO.value());
            Integer result = spuService.isCommissionByShopIdAndSpuId(shopId, spuAdminVO.getSpuId());
            if (!result.equals(0)) {
                //代销了
                spuAdminVO.setIsCommission(IsCommission.YES.value());
            }
        }
        return ServerResponseEntity.success(spuAdminVOS);
    }

    @Override
    public ServerResponseEntity<Void> soldOutSpu(Long skuId, Long price) {
        spuService.soldOutSpu(skuId, price);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<List<SpuVO>> getSupplyPrice(List<Long> spuIds) {

        return null;
    }

    @Override
    public ServerResponseEntity<Void> soldOutSpuBySpu(Long spuId, Long price, Long marketPriceFee) {
        spuService.soldOutSpuBySpu(spuId, price, marketPriceFee);
        return ServerResponseEntity.success();
    }


    @Override
    public ServerResponseEntity<Void> supplierUpdateSpuStatus(Long supplierSpuId, Integer status) {
        //根据供应商品id获取代销商品
        List<SpuVO> commissionSpuList = spuService.listSpuBySupplierSpuId(supplierSpuId);
        List<Long> commissionSpuIdList = commissionSpuList.stream().map(e -> e.getSpuId()).collect(Collectors.toList());
        //供应商下架
        if (Objects.equals(status, SpuStatus.OFF_SHELF.value())) {
            //下架 商家供应商发货的代销商品
            supplierSpuUpdateLaterOperateService.batchChangeSpuStatus(commissionSpuIdList, SpuStatus.OFF_SHELF.value(),SysTypeEnum.MULTISHOP.value());
            //供应商品为下架状态修改代销商品发货方式
            if(Objects.equals(status, SpuStatus.OFF_SHELF.value())){
                //修改发货方式
                spuService.batchUpdateCommissionSpuDeliverType(commissionSpuIdList,SupplierDeliveryType.SHOP_DELIVERY.value());
            }
        }
        //供应商品平台下架
        if (Objects.equals(status, SpuStatus.PLATFORM_OFF_SHELF.value())) {
            //下架
            spuService.batchChangeCommissionSpuStatus(commissionSpuIdList, SpuStatus.OFF_SHELF.value(),SysTypeEnum.MULTISHOP.value());
            //修改发货方式
            spuService.batchUpdateCommissionSpuDeliverType(commissionSpuIdList,SupplierDeliveryType.SHOP_DELIVERY.value());
        }

        //供应商品为删除状态
        if (Objects.equals(status, SpuStatus.DELETE.value())) {
            //下架
            spuService.batchChangeCommissionSpuStatus(commissionSpuIdList, SpuStatus.OFF_SHELF.value(),SysTypeEnum.MULTISHOP.value());
            //修改发货方式
            spuService.batchUpdateCommissionSpuDeliverType(commissionSpuIdList,SupplierDeliveryType.SHOP_DELIVERY.value());
        }
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<List<SpuVO>> getSpuIsSynUpdate(List<Long> spuIds) {
        return ServerResponseEntity.success(spuService.getSpuIsSynUpdate(spuIds));
    }

    @Override
    public ServerResponseEntity<Void> supplierSpuUpdateLaterOffSpu(Long supplierSpuId, Integer commissionSpuOffType) {

        spuService.supplierSpuUpdateLaterOffSpu(supplierSpuId,commissionSpuOffType);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<Void> skuUpdateLaterOperate(Long supplierSpuId) {
        supplierSpuUpdateLaterOperateService.skuUpdateLaterOperate(supplierSpuId);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<Void> skuWeightOrVolumeUpdateOperate(Long supplierSpuId) {
        supplierSpuUpdateLaterOperateService.skuWeightOrVolumeUpdateOperate(supplierSpuId);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<Void> skuAddOperate(Long supplierSpuId) {
        return null;
    }

    @Override
    public ServerResponseEntity<Void> feePriceUnderSupplyPrice(EsProductBO esProductBO) {
        supplierSpuUpdateLaterOperateService.feePriceUnderSupplyPrice(esProductBO);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<Void> soldOutManualPriceCommissionSpu(Long supplierSpuId,Integer type,Integer isFiltration) {
        supplierSpuUpdateLaterOperateService.soldOutManualPriceCommissionSpu(supplierSpuId,type,isFiltration);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<Void> supplierSkuAddOrDeleteLaterOperate(Long supplierSpuId,Long skuId) {
        supplierSpuUpdateLaterOperateService.supplierSkuAddOrDeleteLaterOperate(supplierSpuId,skuId);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<Void> changeSynUpdate(Long supplierSpuId) {
        supplierSpuUpdateLaterOperateService.changeSynUpdate(supplierSpuId);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<Void> updateManualPriceCommissionSpuPrice(Long shopId) {
        spuService.updateManualPriceCommissionSpuPrice(shopId);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<List<SpuAdminVO>> checkCommissionSpuIsUpdateMsg(List<SpuAdminVO> spuAdminVOS) {
        List<Long> supplierSpuIdList = spuAdminVOS.stream().map(SpuAdminVO::getSupplierSpuId).collect(Collectors.toList());
        if (CollUtil.isEmpty(supplierSpuIdList)) {
            return ServerResponseEntity.success(spuAdminVOS);
        }
        List<SpuVO> supplierSpuVOList = spuService.listSpuBySpuIds(supplierSpuIdList);
        if (Objects.isNull(supplierSpuVOList)) {
            return ServerResponseEntity.success(spuAdminVOS);
        }
        Map<Long, List<SpuVO>> supplierSpuMap = supplierSpuVOList.stream().collect(Collectors.groupingBy(SpuVO::getSpuId));
        List<SpuAdminVO> spuAdminVOS1 = supplierSpuUpdateLaterOperateService.disposeSpuMsg(spuAdminVOS,supplierSpuMap);
        return ServerResponseEntity.success(spuAdminVOS1);
    }

    @Override
    public ServerResponseEntity<List<ProductSearchVO>> usCheckCommissionSpuIsUpdateMsg(List<ProductSearchVO> productSearchVOS) {
        List<Long> spuIdList = new ArrayList<>();
        List<Long> supplierSpuIdList = new ArrayList<>();
        for (ProductSearchVO productSearchVO : productSearchVOS) {
            List<Long> spuIds = productSearchVO.getSpus().stream().map(e -> e.getSpuId()).collect(Collectors.toList());
            List<Long> supplierSpuIds = productSearchVO.getSpus().stream().map(e -> e.getSupplierSpuId()).collect(Collectors.toList());
            if (CollUtil.isNotEmpty(spuIds)) {
                spuIdList.addAll(spuIds);
            }
            if (CollUtil.isNotEmpty(supplierSpuIds)) {
                supplierSpuIdList.addAll(supplierSpuIds);
            }
        }

        if (CollUtil.isEmpty(spuIdList) && CollUtil.isEmpty(supplierSpuIdList)) {
            return ServerResponseEntity.success(productSearchVOS);
        }

        //批量获取代销商品基本信息是否改变
        List<SpuConsignmentChange> spuConsignmentChanges = spuConsignmentChangeService.batchGetBySpuIdList(spuIdList);
        Map<Long, List<SpuConsignmentChange>> spuConsignmentChangeMap = spuConsignmentChanges.stream().collect(Collectors.groupingBy(SpuConsignmentChange::getSpuId));
        //批量获取供应商商品信息
        List<SpuVO> supplierSpuVOList = spuService.listSpuBySpuIds(supplierSpuIdList);
        Map<Long, List<SpuVO>> supplierSpuMap = supplierSpuVOList.stream().collect(Collectors.groupingBy(SpuVO::getSpuId));
        for (ProductSearchVO productSearchVO : productSearchVOS) {
            List<SpuSearchVO> spuSearchVOS = supplierSpuUpdateLaterOperateService.usDisposeSpuMsg(productSearchVO.getSpus(),spuConsignmentChangeMap,supplierSpuMap);
            productSearchVO.setSpus(spuSearchVOS);
        }
        return ServerResponseEntity.success(productSearchVOS);
    }

    @Override
    public ServerResponseEntity<Void> updateSaleNumBySeckillOrder(Long spuId, Integer prodCount) {
        spuExtensionService.updateSaleNumBySeckillOrder(spuId, prodCount);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<List<SpuVO>> listSpuBySpuIdsNo(List<Long> spuIds) {
        return ServerResponseEntity.success(spuService.listSpuBySpuIds(spuIds));
    }

    @Override
    public ServerResponseEntity<List<SpuVO>> getDetailBySpuIds(List<Long> spuIdS) {
        List<SpuVO> spuVOS = spuService.getBySpuIds(spuIdS);
        ProductLangUtil.spuList(spuVOS);
        return ServerResponseEntity.success(spuVOS);
    }

    @Override
    public ServerResponseEntity<Void> batchChangeSpuStatusToDisableBySupplierIds(List<Long> supplierIdsToStop) {
        spuService.batchChangeSpuStatusToDisableBySupplierIds(supplierIdsToStop);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<Void> syncUpdateCommissionSpuBrandOrSeq(Long brandId, Integer seq, Long supplierSpuId) {
        spuService.syncUpdateCommissionSpuBrandOrSeq(brandId,seq,supplierSpuId);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<Void> voluntarilyImportSupplierSpu(List<SpuVO> spuVOS, Integer sysType, Long userId) {
        spuService.voluntarilyImportSupplierSpu(spuVOS, sysType, userId);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<Void> updateSpuByShopId(Long shopId, Integer sysType) {
        spuService.updateSpuByShopId(shopId, sysType);
        return ServerResponseEntity.success();
    }
}
